﻿using FileTransferSystem.Services;
using FileTransferSystem.Utilities;

namespace FileTransferSystem
{
    /// <summary>
    /// 程序主入口
    /// </summary>
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("文件传输系统启动...");

            // 初始化历史记录管理器
            var historyManager = new HistoryManager();

            // 初始化传输管理器
            var transferManager = new FileTransferManager(historyManager);

            // 检查是否有未完成的传输
            await transferManager.CheckUnfinishedTransfers();

            // 主循环
            while (true)
            {
                Console.WriteLine("\n请选择操作:");
                Console.WriteLine("1. 发送文件");
                Console.WriteLine("2. 接收文件");
                Console.WriteLine("3. 查看历史记录");
                Console.WriteLine("4. 查询可用端口");
                Console.WriteLine("5. 退出");

                var choice = Console.ReadLine();

                switch (choice)
                {
                    case "1":
                        await transferManager.StartSending();
                        break;
                    case "2":
                        await transferManager.StartReceiving();
                        break;
                    case "3":
                        historyManager.ShowHistory();
                        break;
                    case "4":
                        PortScanner.FindAvailablePorts();
                        break;
                    case "5":
                        Console.WriteLine("程序退出...");
                        return;
                    case "0":
                        Console.WriteLine("已返回主菜单");
                        break;
                    default:
                        Console.WriteLine("无效选择，请重新输入");
                        break;
                }
            }
        }
    }
}